package br.com.engine.menu;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import br.com.engine.Vector2;
import br.com.engine.componentes.GameObject;
import br.com.engine.componentes.SpriteFont;
import br.com.engine.componentes.factory.SpriteFontFactory;
import br.com.engine.interfaces.IComponent;
import br.com.engine.interfaces.IScript;

public class Menu implements IComponent, IScript
{
	private List<GameObject> lFontes;
	private int itemSelecionado = 0;
	
	public Menu( )
	{
		lFontes = new ArrayList<GameObject>( );
	}
	
	@Override
	public void setup( )
	{
		
	}
	
	@Override
	public void update( long time ) 
	{
		for( int i = 0; i < lFontes.size( ); i++ )
		{
			if( i == itemSelecionado )
				lFontes.get( i ).getComponent( SpriteFont.class ).setColor( Color.BLUE );
			else
				lFontes.get( i ).getComponent( SpriteFont.class ).setColor( Color.BLACK );
		}
	}

	@Override
	public void draw( )
	{
		for( int i = 0; i < lFontes.size( ); i++ )
			lFontes.get( i ).getComponent( SpriteFont.class ).draw( );
	}
	
	public void next( )
	{
		if( ( itemSelecionado + 1 ) != lFontes.size( ) )
			itemSelecionado++;
	}
	
	public void previus( )
	{
		if( itemSelecionado != 0 )
			itemSelecionado--;
	}
		
	public int getIndice( )
	{
		return itemSelecionado + 1;
	}
		
	public void add( String texto, int x, int y, int fonteSize )
	{
		GameObject font = SpriteFontFactory.newSpriteFont( texto, new Vector2( x, y ) );
		
		font.getComponent( SpriteFont.class ).setFontSize( fonteSize );
		
		lFontes.add( font );
	}
	
	/**
	 * adiciona em um eixo y, mas centralizando o X
	 * @param texto
	 * @param y
	 * @param fonteSize
	 */
	public void add( String texto, int y, int fonteSize )
	{
		GameObject font = SpriteFontFactory.newSpriteFont( texto, y );
        
        font.getComponent( SpriteFont.class ).setFontSize( fonteSize );
		
		lFontes.add( font );
	}

    public GameObject getGameObject( )
    {
        GameObject gameObject = new GameObject( );
        
        gameObject.addComponente( this );
        gameObject.addScripts   ( this );
        
        return gameObject;
    }
}